clear all
set more off
	
global dir = "C:\Users\mrueda\Documents\Emory\Papers\Networks_persistance\do_files\do_files_APSA21\post_JOP\Replication_BJPS\"	

cd "$dir"

use "Data\cand_level_persist_rep.dta",clear

gen treat=0
replace treat=1 if margin_victory>0&margin_victory~=.
replace treat=. if margin_victory==.

gen treat_margin_victory=treat*margin_victory
gen margin_victory_sq=margin_victory^2
gen treat_margin_victory_sq=treat*margin_victory_sq	



	texdoc close 
	cap erase "$dir/Tables/TableF1.tex"
	texdoc init "$dir/Tables/TableF1.tex", force

	tex \begin{table}[tbph]
	tex \caption{Effect of donating to an election winner on future donations (global quadratic parametric RD)}\label{tab:donations_l}
	tex \centering
	tex \begin{tabular}{l c c H} \hline
	tex Outcome:&  Any race  & Mayor & Other races \\
	tex & (1) & (2) & (3) \\ \hline
	tex & & & \\
	
	*Model 1
	foreach x in donate_15any b5 {
	
		*No Family
		*Regressions
		quietly: regress `x' treat treat_margin_victory_sq margin_victory_sq treat_margin_victory margin_victory , vce(cluster muni_code)
		quietly sum `x' if e(sample)
			local mean_`x' : di %5.3f r(mean)
			local sd_`x' : di %5.3f r(sd) 		
		
		regress `x' treat treat_margin_victory_sq margin_victory_sq treat_margin_victory margin_victory , vce(cluster muni_code)

		local N_`x' : di %5.0f e(N)
		local R2_`x' : di %5.3f e(r2)

		matrix b = e(b)
		matrix v = e(V)
		matrix res=r(table)
		
		local b1_`x' : di %5.3f b[1,1]
		local se1_`x' : di %5.3f sqrt(v[1,1])
		local p_v_`x' :di %5.3f res[4,1]
		local uci_`x': di %5.3f res[6,1]
		local lci_`x': di %5.3f res[5,1]
		
	}

	
	*Continue table
	tex Electoral victory & `b1_donate_15any' & `b1_b5' & `b1_b2b' \\
	tex \ \ \ \ p-value & `p_v_donate_15any' & `p_v_b5' & `p_v_b2b' \\
	tex \ \ \ \ CI 95\%  & [`lci_donate_15any',`uci_donate_15any'] & [`lci_b5',`uci_b5'] & [`lci_b2b',`uci_b2b'] \\
	tex & & & \\
	
	tex Observations & `N_donate_15any' & `N_b5' & `N_b2b' \\
	tex Mean & `mean_donate_15any' & `mean_b5' & `mean_b2b' \\  \hline
	tex \end{tabular}
	tex \parbox{160mm}{ \footnotesize{
	tex \footnotesize{OLS estimates of average treatment effects at the cutoff.  Controls include the interaction of the treatment with running variable and running variable, interaction of the treatment with the squared running variable, and the running variable squared. P-values and 95\% robust confidence intervals with clustering at the municipality level.
	tex }
	tex }
	tex }
	tex \end{table}
	cap texdoc close 
